"""
A module containing helpful method when using the RuthAgent.
"""
import xmlrpclib

def connectAgent(vdsmURI):
    """
    Connect to a Ruth Agent.

    :param vdsmURI: The URI used to connect to vdsm.
    """
    agentAddress = "%s:%d" % (vdsmURI.rsplit(":", 1)[0], 3099)
    agentAddress = agentAddress.replace("https://", "http://")
    agent = xmlrpclib.ServerProxy(agentAddress)
    try:
        agent.ping()
    except:
        raise Exception("Could not connect to agent. Check if it's on.")

    return agent

